// @ts-ignore
import { URI, decode as _decode, encode as _encode } from 'gbk.js'

function getEncodeURI (str: string, char: string) {
  if (char === 'gbk') {
    return URI.encodeURI(str)
  }
  return encodeURI(str)
}

function getEncodeURIComponent (str: string, char: string) {
  if (char === 'gbk') {
    return URI.encodeURIComponent(str)
  }
  return encodeURIComponent(str)
}

function decode (buf: Buffer, char: string) {
  if (char === 'gbk') {
    return _decode(buf)
  }
  return buf
}

function encode (str: string, char: string) {
  if (char === 'gbk') {
    return _encode(str)
  }
  return Buffer.from(str)
}

export {
  getEncodeURI,
  getEncodeURIComponent,
  decode,
  encode
}
